#include "Timer.h"
#include <windows.h>

namespace Broady {

void Timer::Update( void )
{
	unsigned int tick = GetTickCount( );

	m_elapsed = tick - m_current;
	m_current = tick;
	m_accum += m_elapsed;
}

unsigned int Timer::Current( void ) const
{
	return m_current;
}

unsigned int Timer::Elapsed( void ) const
{
	return m_elapsed;
}

bool Timer::Fire( void )
{
	if( m_accum < m_interval )
	{
		return false;
	}

	m_accum -= m_interval;

	return true;
}

void Timer::Reset( void )
{
	m_accum = 0;
	m_elapsed = 0;
	m_current = GetTickCount( );
}

void Timer::Init( unsigned int interval )
{
	m_accum = 0;
	m_elapsed = 0;
	m_interval = interval;
	m_current = GetTickCount( );
}

} // namespace
